package com.ruoyi.web.controller.parties;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.entity.Related;
import com.ruoyi.system.service.RelatedService;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 相关报告信息(Related)表控制层
 * @since 2023-02-07 11:26:23
 */
@RestController
@RequestMapping("/related")
public class RelatedController extends BaseController {

    @Resource
    private RelatedService relatedService;

    /**
     * 分页查询
     * @param related 筛选条件
     * @return 查询结果
     */
    @GetMapping("list")
    public TableDataInfo queryByPage(Related related) {
        startPage();
        List<Related> list = relatedService.queryAll(related);
        return getDataTable(list);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Related> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.relatedService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param related 实体
     * @return 新增结果
     */
    @PreAuthorize("@ss.hasPermi('system:related:add')")
    @PostMapping("add")
    public ResponseEntity<Related> add(@Validated @RequestBody Related related) {
        return ResponseEntity.ok(this.relatedService.insert(related));
    }

    /**
     * 编辑数据
     *
     * @param related 实体
     * @return 编辑结果
     */
    @PreAuthorize("@ss.hasPermi('system:related:update')")
    @PutMapping("edit")
    public ResponseEntity<Related> edit(@Validated @RequestBody Related related) {
        return ResponseEntity.ok(this.relatedService.update(related));
    }

    /**
     * 删除数据
     *
     * @param related 主键
     * @return 删除是否成功
     */
    @PreAuthorize("@ss.hasPermi('system:related:delete')")
    @DeleteMapping("delete")
    public ResponseEntity<Boolean> deleteById(@Validated @RequestBody Related related) {
        return ResponseEntity.ok(this.relatedService.deleteById(related.getId()));
    }

}

